package com.vidyu.businesslayer.businesscomponents;

import com.vidyu.businesslayer.businessentities.Contract;
import com.vidyu.businesslayer.businessentities.Pair;
import com.vidyu.datalayer.dataaccesscomponents.ContractDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: eyalsa
 * Date: 4/16/13
 * Time: 11:55 AM
 * To change this template use File | Settings | File Templates.
 */
@Component
public class ContractHandler {

    @Autowired
    private ContractDao contractDao;

    public Pair<String , String> getTitleAndContent(long id){
        Contract contract = contractDao.findById(id);
        return new Pair<String , String>(contract.getTitle(), contract.getContent());
    }

    public List<Pair<Long, String>> getAllContractTitles(){
        List<Contract> contractList = contractDao.getAllContractTitles();
        List<Pair<Long, String>> pairList = new ArrayList<Pair<Long, String>>();
        for (Contract contract : contractList){
            pairList.add(new Pair<Long, String>(contract.getId(), contract.getTitle()));
        }
        return pairList;
    }
}
